package com.hucheng.activity;

import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
import com.hucheng.activity.query.ExchangeQuery;
import com.hucheng.activity.query.LuckPrizeQuery;
import com.hucheng.activity.service.ExchangeService;
import com.hucheng.activity.service.LuckPrizeService;
import com.hucheng.activity.vo.LuckPrizeVO;
import com.hucheng.common.config.aspect.DynamicDataSourceAspect;
import com.hucheng.common.config.db.DynamicDataSourceRegister;
import com.hucheng.common.page.CommonPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.List;

@SpringBootApplication
@EnableDubboConfiguration
@EnableTransactionManagement
@Import(value = {DynamicDataSourceRegister.class, DynamicDataSourceAspect.class})
public class DubboActivityProviderApplication implements CommandLineRunner {

    @Autowired
    private LuckPrizeService luckPrizeService;

    @Autowired
    private ExchangeService exchangeService;

    public static void main(String[] args) {
        SpringApplication.run(DubboActivityProviderApplication.class, args);
    }

    @Override
    public void run(String... strings) throws Exception {
        //初始化活动配置到redis
        LuckPrizeQuery luckPrizeQuery = new LuckPrizeQuery();
        luckPrizeQuery.setStatus(1);
        luckPrizeQuery.setPageParameter(null);
        luckPrizeService.initLuckPrizeList(luckPrizeQuery);

        //初始化兑换奖励配置
        ExchangeQuery exchangeQuery = new ExchangeQuery();
        exchangeQuery.setStatus(1);
        exchangeQuery.setPageParameter(null);
        exchangeService.initExchangeList(exchangeQuery);
    }
}
